home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / checktv.exe / CHECK.CPP < prev   
C/C++ Source or Header  |  1992-10-09  |  2KB  |  105 lines

  1. /*
  2.  * CHECK.CPP
  3.  *
  4.  * Ezra Shabi
  5.  * October 9, 1992
  6.  *
  7.  */
  8.  
  9.  
  10. #define Uses_TApplication
  11. #define Uses_TKeys
  12. #define Uses_TRect
  13. #define Uses_TMenuBar
  14. #define Uses_TSubMenu
  15. #define Uses_TMenuItem
  16. #define Uses_TStatusLine
  17. #define Uses_TDeskTop
  18.  
  19. #include    <string.h>
  20. #include    <tv.h>
  21.  
  22. const int cmCheckItem1 = 200;            // new commands definitions
  23. const int cmCheckItem2 = 201;
  24.  
  25. const char *Item1 = "[ ] Check item ~1~";    // check items names
  26. const char *Item2 = "[ ] Check item ~2~";
  27.  
  28. int Flag1 = 1;                    // check items flags
  29. int Flag2 = 0;
  30.  
  31. class TMyApp : public TApplication
  32. {
  33. public:
  34.     TMyApp();
  35.     static TMenuBar *initMenuBar( TRect r );
  36.     virtual void handleEvent( TEvent& event);
  37.     void SetCheckedItem(TMenuItem *item, int flag);
  38.     static TMenuItem *CheckMenuItem1, *CheckMenuItem2;
  39. };
  40.  
  41. TMenuItem *TMyApp::CheckMenuItem1;        // define check menu items
  42. TMenuItem *TMyApp::CheckMenuItem2;
  43.  
  44. TMyApp::TMyApp() :
  45.     TProgInit(&TMyApp::initStatusLine,
  46.           &TMyApp::initMenuBar,
  47.           &TMyApp::initDeskTop)
  48. {
  49.     SetCheckedItem(CheckMenuItem1, Flag1);    // init check menu items
  50.     SetCheckedItem(CheckMenuItem2, Flag2);
  51. }
  52.  
  53. TMenuBar *TMyApp::initMenuBar( TRect r )
  54. {
  55.     r.b.y = r.a.y + 1;
  56.                         // create check menu objects
  57.     CheckMenuItem1 = new TMenuItem(Item1, cmCheckItem1, kbNoKey);
  58.     CheckMenuItem2 = new TMenuItem(Item2, cmCheckItem2, kbNoKey);
  59.  
  60.     return new TMenuBar( r,            // create the menu bar
  61.         *new TSubMenu("~M~enu", kbAltM)+
  62.             *CheckMenuItem1+
  63.             *CheckMenuItem2+
  64.             newLine()+
  65.             *new TMenuItem("E~x~it", cmQuit, cmQuit, hcNoContext, "Alt-X" )
  66.     );
  67. }
  68.  
  69. void TMyApp::handleEvent(TEvent& event)
  70. {
  71.     TApplication::handleEvent(event);
  72.     if( event.what == evCommand ) {
  73.         switch( event.message.command ) {
  74.         case cmCheckItem1:        // menu item 1
  75.             Flag1 = !Flag1;
  76.             SetCheckedItem(CheckMenuItem1, Flag1);
  77.             break;
  78.         case cmCheckItem2:        // menu item 2
  79.             Flag2 = !Flag2;
  80.             SetCheckedItem(CheckMenuItem2, Flag2);
  81.             break;
  82.         default:
  83.             return;
  84.         }
  85.         clearEvent( event );        // clear event after handling
  86.     }
  87. }
  88.  
  89. void TMyApp::SetCheckedItem(TMenuItem *item, int flag)
  90. {
  91.     char far *cp;
  92.  
  93.     cp = strchr(item->name, '[') + 1;       // find the "[" char
  94.     *cp = (flag) ? 'X' : ' ';        // and place ' ' or 'X'
  95.     return;                    // right after it.
  96. }
  97.  
  98. int main()
  99. {
  100.     TMyApp    myApp;
  101.  
  102.     myApp.run();
  103.     return 0;
  104. }
  105.